package com.tenglong.teacher.ui.adapter.viewholder;


import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;
import com.tenglong.teacher.R;
import com.tenglong.teacher.data.resultInfo.ClassInfo;
import com.tenglong.teacher.data.resultInfo.ClassInfoBean;
import com.tenglong.teacher.ui.adapter.HomePagerAdapter;
import com.tenglong.teacher.ui.adapter.viewholder.base.BaseViewHolder;


/**
 * @author hdx on 2019/3/27.
 */
public class ClassRecordViewHolder extends BaseViewHolder<ClassInfoBean> implements View.OnClickListener {
    private TextView className, subject, time, reissueHomework;
    private ClassInfo data;
    private HomePagerAdapter.ClassRecordListener listener;

    public ClassRecordViewHolder(View itemView) {
        super(itemView);
        initView();
        setListeners();
    }

    public ClassRecordViewHolder(View itemView, HomePagerAdapter.ClassRecordListener listener) {
        this(itemView);
        this.listener = listener;
    }

    private void setListeners() {
        reissueHomework.setOnClickListener(this);
    }

    private void initView() {
        className = itemView.findViewById(R.id.className);
        subject = itemView.findViewById(R.id.subject);
        time = itemView.findViewById(R.id.time);
        reissueHomework = itemView.findViewById(R.id.reissueHomework);
    }

    @Override
    public void setLayoutInfo(ClassInfoBean classInfoBean) {
        this.data = (ClassInfo) classInfoBean;
        className.setText(data.name == null ? "" : data.name);
        time.setText( (TextUtils.isEmpty(data.to) ? "" : ("  " + data.from.substring(0,5) + "-" + data.to.substring(0,5))));
        subject.setText("（" + data.courseName + "）");
        reissueHomework.setSelected(data.isCheck);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.reissueHomework:
                data.isCheck=!data.isCheck;
                reissueHomework.setSelected(data.isCheck);
                if (listener != null) {
                    listener.onRecordPosition(getLayoutPosition());
                }
                break;
        }
    }
}
